package org.jtb.quickr;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jdom.Element;

/**
 * Sizes response.
 *
 * @see org.jtb.quickr.PeopleService#getInfo(String)
 */
public class SizesResponse extends FlickrResponse {
    /**
     * Sizes size response.
     */
    public static class Size extends FlickrResponse {
        private String label;
        private String source;
        private URL url;
        private int height;
        private int width;
        
        public Size(Element e) throws QuickrException {
            super(e);
        }
        
        protected void populate(Element e) {
            this.label = e.getAttributeValue("label");
            this.source = e.getAttributeValue("source");
            this.url = getAttrUrl(e, "url");
            this.height = getAttrInt(e, "height");
            this.width = getAttrInt(e, "width");
        }

        public String getLabel() {
            return label;
        }

        public String getSource() {
            return source;
        }

        public URL getUrl() {
            return url;
        }

        public int getHeight() {
            return height;
        }

        public int getWidth() {
            return width;
        }
    }
        
    private List<Size> sizes;
    
    SizesResponse(InputStream is) throws QuickrException {
        super(is);
    }
    
    protected void populate(Element e) throws QuickrException {
        sizes = new ArrayList<Size>();        
        List sizeElements = e.getChild("sizes").getChildren("size");

        for (Iterator i = sizeElements.iterator(); i.hasNext(); ) {
            Element sizeElement = (Element)i.next();
            Size s = new Size(sizeElement);
            sizes.add(s);
        }
    }

    public List<Size> getSizes() {
        return sizes;
    }
}
